//
//  SFStatusBottomView.swift
//  SFWeiBo
//
//  Created by 孙凡 on 16/4/12.
//  Copyright © 2016年 Edward. All rights reserved.
//

import UIKit

class SFStatusBottomView: UIView {


    var statusViewModel: SFStatusViewModel?{

        didSet{

            //设置数据

            //消息
            one.setTitle(statusViewModel?.reposts, forState: UIControlState.Normal)
//            print(statusViewModel?.reposts)

            //转发
            two.setTitle(statusViewModel?.comments, forState: UIControlState.Normal)
            //点赞
            three.setTitle(statusViewModel?.attitudes, forState: .Normal)
        }

    }

    private var one: UIButton!
    private var two: UIButton!
    private var three: UIButton!


    override init(frame: CGRect) {

        super.init(frame: frame)

        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }


    private func setupUI(){

        self.backgroundColor = SFRandom()

        //添加按钮
        one = addButton(imageName: "timeline_icon_comment", title: "消息")
        two = addButton(imageName: "timeline_icon_retweet", title: "转发")
        three = addButton(imageName: "timeline_icon_unlike", title: "点赞")

        //添加分割线
        addSubview(splite1)
        addSubview(splite2)


        //设置约束

        one.snp_makeConstraints { (make) in

            make.top.leading.bottom.equalTo(self)
            make.width.equalTo(two)
        }
        two.snp_makeConstraints { (make) in

            make.top.bottom.equalTo(self)
            make.leading.equalTo(one.snp_trailing)
            make.width.equalTo(three)
        }
        three.snp_makeConstraints { (make) in

            make.top.bottom.trailing.equalTo(self)
            make.leading.equalTo(two.snp_trailing)

        }

        //分割线的约束
        splite1.snp_makeConstraints { (make) in

            make.centerX.equalTo(one.snp_trailing)
            make.centerY.equalTo(self)
        }

        splite2.snp_makeConstraints { (make) in

            make.centerX.equalTo(two.snp_trailing)
            make.centerY.equalTo(self)
        }
    }

    //添加按钮的方法
    private func addButton(imageName imageName:String, title:String) -> UIButton{

        let btn = UIButton()

        btn.setImage(UIImage(named: imageName), forState: UIControlState.Normal)

        btn.setTitle(title, forState: UIControlState.Normal)

        btn.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)

        btn.setBackgroundImage(UIImage(named: "timeline_retweet_background"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "timeline_retweet_background_highlighted"), forState: UIControlState.Highlighted)


        self.addSubview(btn)

        return btn
    }

    //分割线
    private lazy var splite1: UIImageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
    private lazy var splite2: UIImageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))


}
